package com.villaday.idf.adapter;

import android.content.Context;
import android.graphics.Paint;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.villaday.idf.R;
import com.villaday.idf.base.AbsRecyclerViewAdapter;
import com.villaday.idf.base.OnAdapterCallbackListener;
import com.villaday.idf.model.PresellEntity;
import com.villaday.idf.model.RecommendEntity;
import com.villaday.idf.model.RefreshtokenEntity;
import com.villaday.idf.util.PhoneUtil;
import com.villaday.idf.util.SharedPreferencesUtil;

/**
 * 首页动态列表
 */

public class HomeListFindAdapter extends AbsRecyclerViewAdapter<RecommendEntity.BodyEntity.DataListEntity> {
    private OnAdapterCallbackListener onAdapterCallbackListener;
    private View.OnClickListener onClickListener;
    private final String roleType;

    public HomeListFindAdapter(Context context, OnAdapterCallbackListener onAdapterCallbackListener, View.OnClickListener onClickListener) {
        super(context, R.layout.item_focus, R.layout.item_page_loading,
                R.layout.item_page_bottom);
        this.onAdapterCallbackListener = onAdapterCallbackListener;
        this.onClickListener = onClickListener;
        RefreshtokenEntity.BodyBean roleInfo =
                SharedPreferencesUtil.getRoleInfo(context);
        roleType = roleInfo.getMember().getType();

    }

    @Override
    public int getItemType(RecommendEntity.BodyEntity.DataListEntity d) {
        return d.getMyType();
    }

    @Override
    public void onBindHolder(AbsRecyclerViewAdapter.RecyclerViewHolder holder, RecommendEntity.BodyEntity.DataListEntity d, int position) {
        switch (d.getMyType()) {

            case 0: {
                String tag = "";
                if (!(d.getTags() == null || d.getTags().size() == 0)) {

                    for (int i = 0; i < d.getTags().size(); i++) {
                        tag = new StringBuilder().append(tag).append("#").append(d.getTags().get(i)).append("#").append(" ").toString();
                    }
                }

                holder.bindSimpleDraweeView(R.id.sdv, TextUtils.isEmpty(d.getVideo().getVideoUrl())?d.getImageURL() + "":d.getVideo().getPosterUrl())
                        .bindTextView(R.id.tv_description, tag)
                        .bindTextView(R.id.tv_addr, d.getProvince() + "·" + d.getCity())
                        .setViewVisible(R.id.tv_addr, (TextUtils.isEmpty(d.getProvince()) &&TextUtils.isEmpty(d.getCity())?View.INVISIBLE:View.VISIBLE) )

                        .bindTextView(R.id.tv_title, d.getDescription())
                        .bindSimpleDraweeView(R.id.sdv_head, d.getMember().getHeaderUrl() + "")
                        .bindTextView(R.id.tv_name, d.getMember().getNickName())
                        .bindTextView(R.id.tv_order_type, d.getFavoriteCount() == null ? "0" : d.getFavoriteCount())
                        .bindTextView(R.id.tv_share, d.getShareCount() == null ? "0" : d.getShareCount())
                        .setViewSelected(R.id.tv_order_type, d.isFavorite())
                .setViewVisible(R.id.tv_play, TextUtils.isEmpty(d.getVideo().getVideoUrl())?View.GONE:View.VISIBLE);





               /* holder.bindTextView(R.id.tv_remai, d.getHouse().getAddress())
                        .bindSimpleDraweeView(R.id.sdv, d.getHouse().getImageURL())
                        .bindTextView(R.id.tv_description, d.getHouse().getRoomNum() + "室" + d.getHouse().getHallNum() + "厅" + d.getHouse().getBedNum() + "床" + "  |  " + d.getHouse().getAcreage() + "㎡" + "  |  " + "宜住" + d.getHouse().getPeopleNum() + "人")
                        .bindTextView(R.id.tv_addr, "截止日期：" + d.getExpiredDate())
                        .bindTextView(R.id.tv_name, d.getName())
                        .bindTextView(R.id.tv_zhuanNum, PhoneUtil.handleBalance(d.getBrokerAge() / 100.0 + "", 2))

                        .bindTextViewWithHtml(R.id.tv_price, "&yen;" + (d.getCurrentPrice()==0?"0.00":PhoneUtil.handleBalance(d.getCurrentPrice()/100.0+"",2)))
*//*
                        .bindTextView(R.id.tv_zhe, d.getOriginalPrice()==0?"0.0折":new BigDecimal(((double) d.getCurrentPrice() * 10/ (double)d.getOriginalPrice()) ).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue() + "折")
*//*
                        .bindTextView(R.id.tv_zhe, d.getOriginalPrice()==0?"0.0折":(((double) d.getCurrentPrice() * 10/ (double)d.getOriginalPrice())+"").substring(0,3)+ "折")
                        .bindTextViewWithHtml(R.id.tv_delete, "&yen;" +(d.getOriginalPrice()==0?"0.00":PhoneUtil.handleBalance(d.getOriginalPrice()/100.0+"",2)))
                        .bindTextViewWithHtml(R.id.textView3, "&yen;")

                  .setClickListenerAndTag(R.id.tv_tuiguang, onClickListener, position)
                        .setViewVisible(R.id.tv_zhuan,"0".equals(roleType)?View.GONE:View.VISIBLE)
                        .setViewVisible(R.id.textView3,"0".equals(roleType)?View.GONE:View.VISIBLE)
                        .setViewVisible(R.id.tv_zhuanNum,"0".equals(roleType)?View.GONE:View.VISIBLE)
                        .setViewVisible(R.id.tv_tuiguang,"0".equals(roleType)?View.GONE:View.VISIBLE);

                TextView view = (TextView) holder.getView(R.id.tv_delete);
//添加删除线
                view.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);*/
               /* holder.setClickListenerAndTag(R.id.img_collect, onClickListener, position)
                        .setClickListenerAndTag(R.id.tv_erweima, onClickListener, position)
                        .setClickListenerAndTag(R.id.tv_share1, onClickListener, position);
                FoldTextView ftv = (FoldTextView) holder.getView(R.id.ftv);
                ftv.setText("111111123111111123阿斯顿发阿斯顿发送到大111111123阿斯顿发阿斯顿发送到大111111123阿斯顿发阿斯顿发送到大111111123阿斯顿发阿斯顿发送到大111111123阿斯顿发阿斯顿发送到大阿斯顿发阿斯顿发送到大。厦法定阿萨【德法师打发斯蒂芬撒地】方阿萨德法师打发斯问问蒂芬撒地方阿萨德法师打发斯蒂。芬撒地方发送到发送到发送到发送到发送到发送，到发送到发送到发送到，发送111111123阿斯顿发阿斯顿发送到大。厦法定阿萨【德法师打发斯蒂芬撒地】方阿萨德法师打发斯问问蒂芬撒地方阿萨德法师打发斯蒂。芬撒地方发送到发送到发送到发送到发送到发送，到发送到发送到发送到，发送");
*/
            }
            break;

            case 1: {
                onAdapterCallbackListener.onCallback();
            }
            break;


        }
    }
}
